#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=105;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-48,ch=getchar();}
	return x*f;
}
int T,n,sa[N],ma[N],m[N],a[N];
pair<string,int> st[N];
bool hav;

void dfs(int pos){
	if(pos==n){
		string s;
		for(int i=0;i<2*n-1;i++){
			m[i]=0;
			if(i&1){
				int p1=i/2,p2=p1+1;
				while(p1>=0&&p2<n&&a[p1]==a[p2]) m[i]+=2,p1--,p2++;
			}
			else{
				int p1=i/2-1,p2=p1+2;
				m[i]++;
				while(p1>=0&&p2<n&&a[p1]==a[p2]) m[i]+=2,p1--,p2++;
			}
			if(m[i]!=ma[i]) return;
		}			
		
		for(int i=n-1;~i;i--){
			s=char(a[i]+'a')+s;
			st[i]={s,i};
		}
		sort(st,st+n);
		for(int i=0;i<n;i++)
			if(st[i].second!=sa[i]) return;

		for(int i=0;i<n;i++) cout<<char(a[i]+'a');
		cout<<"\n";
		hav=1;
		return;
	}
	for(int i=0;i<n;i++){
		a[pos]=i;
		dfs(pos+1);
		if(hav) return;
	}
	return;
}

signed main(){
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
    T=read();
	while(T--){
		n=read();
		if(n>8) return 0;
		for(int i=0;i<n;i++) sa[i]=read();
		for(int i=0;i<2*n-1;i++) ma[i]=read();
		hav=0,dfs(0);
		if(!hav) puts("-1");
	}
	return 0;
}